<template>
    <view>
        <view class="uni-common-mt">
            <view>
                <map :latitude="latitude" :longitude="longitude" :markers="markers" >
                </map>
            </view>
			<view>
				<button type="primary" class="no-border confirm-btn" @click="toMap">打开导航</button>
			</view>
        </view>
    </view>
</template>
<script>
    export default {
        data() {
            return {
                title: 'map',
                latitude: 45.696202,
                longitude: 126.586382,
				markers: [{
                    title:'唯果健身工作室',
                    latitude: 45.696202,
                    longitude: 126.586382,
					width: 30,
                    height: 30,
                    iconPath: '../../static/map/A.png'
                }]
            }
        },
        methods: {
			toLocation:function(){
			uni.getLocation({
				type: 'wgs84',
				success: function (res) {
					console.log('当前位置的经度：' + res.longitude);
					console.log('当前位置的纬度：' + res.latitude);
				}
			});
			},
			toMap(){
				var url = "";  
				if (plus.os.name=="Android") {  
					var hasBaiduMap = plus.runtime.isApplicationExist({pname:'com.baidu.BaiduMap',action:'baidumap://'});  
					var hasAmap = plus.runtime.isApplicationExist({pname:'com.autonavi.minimap',action:'androidamap://'});  
					var urlBaiduMap = "baidumap://map/marker?location=39.968789,116.347247&title=DCloud&src=Hello%20uni-app";  
					var urlAmap = "androidamap://viewMap?sourceApplication=Hello%20uni-app&poiname=DCloud&lat=39.9631018208&lon=116.3406135236&dev=0"  
					if (hasAmap && hasBaiduMap) {  
						plus.nativeUI.actionSheet({title:"选择地图应用",cancel:"取消",buttons:[{title:"百度地图"},{title:"高德地图"}]}, function(e){  
							switch (e.index){  
								case 1:  
									plus.runtime.openURL(urlBaiduMap);  
									break;  
								case 2:  
									plus.runtime.openURL(urlAmap);  
									break;  
							}  
						})  
					}  
					else if (hasAmap) {  
						plus.runtime.openURL(urlAmap);  
					}  
					else if (hasBaiduMap) {  
						plus.runtime.openURL(urlBaiduMap);  
					}  
					else{  
						url = "geo:39.96310,116.340698?q=%e6%95%b0%e5%ad%97%e5%a4%a9%e5%a0%82";  
						plus.runtime.openURL(url); //如果是国外应用，应该优先使用这个，会启动google地图。这个接口不能统一坐标系，进入百度地图时会有偏差  
					}  
				} else{  
					// iOS上获取本机是否安装了百度高德地图，需要在manifest里配置，在manifest.json文件app-plus->distribute->apple->urlschemewhitelist节点下添加（如urlschemewhitelist:["iosamap","baidumap"]）  
					plus.nativeUI.actionSheet({title:"选择地图应用",cancel:"取消",buttons:[{title:"Apple地图"},{title:"百度地图"},{title:"高德地图"}]}, function(e){  
						console.log("e.index: " + e.index);  
						switch (e.index){  
							case 1:  
								url = "http://maps.apple.com/?q=%e6%95%b0%e5%ad%97%e5%a4%a9%e5%a0%82&ll=39.96310,116.340698&spn=0.008766,0.019441";  
								break;  
							case 2:  
								url = "baidumap://map/marker?location=39.968789,116.347247&title=DCloud&src=Hello%20uni-app";  
								break;  
							case 3:  
								url = "iosamap://viewMap?sourceApplication=Hello%20uni-app&poiname=DCloud&lat=39.9631018208&lon=116.3406135236&dev=0";  
								break;  
							default:  
								break;  
						}  
						if (url!="") {  
							plus.runtime.openURL( url, function( e ) {  
								plus.nativeUI.alert("本机未安装指定的地图应用");  
							});  
						}  
					})  
				}  
            }
        }
    }
</script>
<style>
    map {
        width: 100%;
        height: 750rpx;
    }
    .test{
        background: #fff;
        height: 100upx;
        text-align: center;
        display: flex;
        margin: 30upx;
    }
	.text_left{
		border-left:2rpx solid #F2F2F2;
	}
	.margin-bot {
		margin-bottom: 100upx;
	}
	.solid-bottom::after {
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
	border-top: 1px solid rgba(0, 0, 0, 0.1);
}
</style>